var Alarm = {
    id: "alarmTable",//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    deptid:0
};

Alarm.initColumn = function () {
    var columns = [
        {field: 'selectItem', checkbox: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '报警类型', field: 'alarmType', align: 'center', valign: 'middle', sortable: true},
        {title: '报警来源', field: 'type', align: 'center', valign: 'middle', sortable: true,
        	formatter : function(value, row,index) {
				if (value == "0") {
					return '自动触发';
				} else if (value == "1") {
					return '人为触发';
				}
			}
        
        },
        {title: '处理状态', field: 'results', align: 'center', valign: 'middle', sortable: true,
        	formatter : function(value, row,index) {
				if (value == "0") {
					return '未处理';
				} else if (value == "1") {
					return '误报';
				}else if (value == "2") {
					return '已处理';
				}else if (value == "3") {
					return '转审批流';
				}
			}
        },
        {title: '是否播报通知', field: 'isBroadcast', align: 'center', valign: 'middle', sortable: true,
        	formatter : function(value, row,index) {
				if (value == "0") {
					return '否';
				} else if (value == "1") {
					return '是';
				}
			}
        },
        {title: '报警设备', field: 'partId', align: 'center', valign: 'middle', sortable: true},
        {title: '创建时间', 
        	field: 'createTime',
        	align: 'center',
        	valign: 'middle',
        	sortable: true
        }
        //{title: '状态', field: 'status', align: 'center', valign: 'middle', sortable: true}
        ];
    return columns;
};

Alarm.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Alarm.seItem = selected;
        return true;
    }
};


Alarm.singleCheck = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
    	if (selected.length >1) {
            Feng.info("请先选中表格中的一条记录进行操作！");
            return false;
        }else{
        	Alarm.seItem = selected[0];
             return true;
        } 
    	
       
    }
};


Alarm.openAlarmView = function () {
    if (this.singleCheck()) {
        var index = layer.open({
            type: 2,
            title: '编辑字典',
            area: ['800px', '500px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/alarm/view_detail/' + Alarm.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 点击修改按钮时
 * @param PartTypeId 管理员id
 */		
Alarm.openChangeAlarm = function () {
    if (this.singleCheck()) {
        var index = layer.open({
            type: 2,
            title: '编辑用户',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/alarm/edit/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};


Alarm.reply = function () {
    if (this.singleCheck()) {
        var index = layer.open({
            type: 2,
            title: '编辑用户',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/alarm/reply/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};




$(function () {
    var defaultColunms = Alarm.initColumn();
    var table = new BSTable("alarmTable", "/alarm/list", defaultColunms);
    table.setPaginationType("server");
    Alarm.table = table.init();
});





